/**
 * 2018年12月16日上午7:05:08
 * @author 谢进财
 */
package com.baihang.project.ds.webSocket.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

import com.baihang.framework.kit.PropKit;
import com.baihang.project.ds.webSocket.handler.DsWebSocketHandler;
import com.baihang.project.ds.webSocket.interceptor.DsWebSocketInterceptor;

/**
 * @author whati
 *
 */
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.springframework.web.socket.config.annotation.WebSocketConfigurer#
	 * registerWebSocketHandlers(org.springframework.web.socket.config.annotation.
	 * WebSocketHandlerRegistry)
	 */
	@Override
	public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
		registry.addHandler(DsWebSocketHandler(), "/Ds").addInterceptors(new DsWebSocketInterceptor())
				.setAllowedOrigins(PropKit.get("websocketDomain"));
		registry.addHandler(DsWebSocketHandler(), "/Ds/sockjs").addInterceptors(new DsWebSocketInterceptor())
				.setAllowedOrigins(PropKit.get("websocketDomain")).withSockJS();
	}

	/*
	 * @Bean public MyWebSocketHandler MyWebSocketHandler() { return new
	 * MyWebSocketHandler(); }
	 */
	@Bean
	public DsWebSocketHandler DsWebSocketHandler() {
		return new DsWebSocketHandler();
	}
}
